package com.lwei.tallybook.client.controller;

import com.lwei.tallybook.base.domain.Account;
import com.lwei.tallybook.base.dto.Message;
import com.lwei.tallybook.service.service.AccountService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * tally-book
 *
 * @author sks.lwei
 * @date 2020/3/18 0018 14:05
 */
@RestController
@RequestMapping("/setting")
public class SettingController extends BaseController{

    @Resource
    private AccountService accountService;

    @PostMapping("/changePassword")
    public Message changePassword(String oldPassword, String password){
        Account account = currentUser();
        boolean validation = accountService.validationPassword(account, oldPassword);
        if(validation){
            accountService.changePwd(account, password);
            return Message.SUCCESS;
        }else {
            return Message.failMsg("原密码验证失败");
        }
    }
}
